<?PHP

  //print_r($_SERVER);
  if(isset($_SESSION["CMS_User"]) && $_SESSION["CMS_User"]!=""){
    $sql='select * from tags where id
    in (select tagrol.TagID from tagrol,userrol where tagrol.RolID=userrol.RolID and userrol.UserID='.$_SESSION["CMS_User"]["ID"].')
    or id in (select TagID from tagrol where RolID=1)';
  }else{
     $sql='select * from tags where id
     in (select tagrol.TagID from tagrol where tagrol.RolID=1)';
  }
  $_rd=mysql_query($sql,$_db_link);
  echo '      <div class="menubakground">
                 <div class="menumain">
                 <ul>';
  while($data=mysql_fetch_array($_rd, MYSQL_ASSOC)){
      $menulist[]=$data;
  }
  
  foreach($menulist as $data){
 //echo "(".$data["ID"]."|".$data["ParentID"]."|".$data["ShowMenu"].")";
    if(!$data["ParentID"]&& $data["ShowMenu"]!=0){
	 
        echo '<li class="menuitemLevel1">
              <a href="'.$_SERVER["SCRIPT_NAME"].'?tag='.$data["ID"].'"><div class="divlink">';
        echo  $data["MenuTitel"];
        echo '</div></a>';
        SubmenuPrint($data["ID"],$menulist);
        echo '</li>';
    }
  }
  echo '</ul></div></div>';
  function SubmenuPrint($parentid,$menulist){
      $str="";
      foreach ($menulist as $data){
          if($parentid==$data["ParentID"] && $data["ShowMenu"]!=0){
              $str=$str.'<li class="subitem"><a href="'.$_SERVER["SCRIPT_NAME"].'?tag='.$data["ID"].'"><div class="divlink">'.$data["MenuTitel"].'</div></a></li>';
          }
      }
      if($str!=""){
          echo '<div class="submenu"><ul>';
          echo $str;
          echo '</ul></div>';
      }
  }

?>

